//
//  ERTHTVC.m
//  EnjoyRunning
//
//  Created by ljm on 2017/3/15.
//  Copyright © 2017年 ljm. All rights reserved.
//

#import "ERTHTVC.h"

#import "ERRunnersVC.h"
#import "ERDiscoverVC.h"
#import "ERRunningVC.h"
#import "ERMineVC.h"
#import "ERMoreVC.h"

@interface ERTHTVC ()

/*
 *    用一个数组装子控制器
 */
@property(nonatomic,strong) NSMutableArray <UIViewController*>* childVC;

@end

@implementation ERTHTVC

#pragma mark -- 重写初始化方法
- (instancetype)init
{
    self = [super init];
    if (self) {
        /*
         *    没有选中时tabbar字体的颜色
         */
        self.tabBar.unselectedItemTintColor = [UIColor blackColor];
        
        /*
         *   选中时tabbar字体的颜色
         */
        self.tabBar.tintColor = [UIColor colorWithHex:0xff6d02];
        
    
        self.tabBar.backgroundColor = [UIColor redColor];
        self.tabBar.barTintColor = [UIColor whiteColor];
        self.tabBar.alpha = 0.9;
        self.tabBar.opaque = YES;
        self.tabBar.translucent = NO;
        
        self.childVC = [NSMutableArray array];
        
        [self addChildVCs];
    }
    return self;
}

#pragma mark -- 添加子视图的方法
- (void)addChildVCs
{
    /*
     *    跑圈 -------- runners
     */
    [self addChildVCWithTitle:@"跑圈" withClassName:@"ERRunnersVC" withNormalImageName:@"contact_normal" withSelectImageName:@"contact_select"];
    
    /*
     *    发现 -------- discover
     */
    [self addChildVCWithTitle:@"发现" withClassName:@"ERDiscoverVC" withNormalImageName:@"discover_normal" withSelectImageName:@"discover_select"];
    
    /*
     *    运动 -------- exercise
     */
    [self addChildVCWithTitle:@"运动" withClassName:@"ERRunningVC" withNormalImageName:@"exercise_normal" withSelectImageName:@"exercise_select"];
    
    /*
     *    我的 -------- mine
     */
    [self addChildVCWithTitle:@"我的" withClassName:@"ERMineVC" withNormalImageName:@"mine_normal" withSelectImageName:@"mine_select"];
    
    /*
     *   更多 -------- more
     */
    [self addChildVCWithTitle:@"更多" withClassName:@"ERMoreVC" withNormalImageName:@"more_normal" withSelectImageName:@"more_select"];
    
    /*
     *    默认选中的tabbar；是中间“运动”
     */
    self.selectedIndex = 2;
}

#pragma mark -- 自定义视图的相关方法
/*
 *    视图的名字 -----  title
 */

/*
 *    类名 ------- className
 */

/*
 *    默认图片的名字 ------------ normalImageName
 */

/*
 *    选中图片的名字 ------------ SelectImageName
 */
- (void)addChildVCWithTitle:(NSString *)title withClassName:(NSString *)className withNormalImageName:(NSString *)normalImageName withSelectImageName:(NSString *)selectImageName
{
    /*
     *    类名转换成字符串
     */
    UIViewController *vc = [NSClassFromString(className) new];
    
    /*
     *    保持图片原色渲染
     */
    UIImage *normalImage = [UIImage imageNamed:normalImageName];
    normalImage = [normalImage
                   imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UIImage *selectImage = [UIImage
                            imageNamed:selectImageName];
    selectImage = [selectImage
                   imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    /*
     *    设置tabbar
     */
    vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:normalImage selectedImage:selectImage];
    
    /*
     *    标题
     */
    vc.title = title;
    
    /*
     *    给子控制器设置导航栏
     */
    UINavigationController *nvc = [[UINavigationController alloc]
                                   initWithRootViewController:vc];
    
    /*
     *    将子控制器添加到数组中
     */
    [self.childVC addObject:nvc];
    
    /*
     *    这里设置的控制器就是系统所需控制器
     */
    self.viewControllers = self.childVC;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
